package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.InventoryDull;

@Transactional(readOnly = true)
public interface InventoryDullRepository extends JpaRepository<InventoryDull, String> {

	/**
	 * 价格单主机降库可替换设备数据
	 */
	// 根据key值查询呆滞库可替换设备（可用数大于零数据）
	@Query(" select i from InventoryDull i where i.material like '%'+?1+'%' or i.name like '%'+?1+'%' or i.figureNum like '%'+?1+'%'and i.usableNum>0")
	Page<InventoryDull> findInventoryDull(String key, Pageable pageable);

	// 得到可替换数据查询数据条数
	@Query("select count(*) from InventoryDull i where i.material like '%'+?1+'%' or i.name like '%'+?1+'%' or i.figureNum like '%'+?1+'%' and i.usableNum>0")
	long findCount(String key);

	// 呆滞库可替换设备
	@Query("select i from InventoryDull i where i.usableNum>0")
	Page<InventoryDull> findNoReplace(Pageable pageable);

	// 得到可替换设备数据条数
	@Query("select count(*) from InventoryDull i where i.usableNum>0")
	long findNoReplaceCount();

	/**
	 * 呆滞库差查询页面查询
	 */
	// 查询数据
	@Query("select i from InventoryDull i where i.material like '%'+?1+'%' or i.name like '%'+?1+'%' or i.figureNum like '%'+?1+'%'")
	Page<InventoryDull> findInventoryDullBykey(String key, Pageable pageable);

	// 得到查询条数
	@Query("select count(*) from InventoryDull i where i.material like '%'+?1+'%' or  i.name like '%'+?1+'%' or i.figureNum like '%'+?1+'%'")
	long getCountBy(String key);

}
